<?php defined('SYSPATH') or die('No direct script access.');
 
class Model_Articles extends ORM {
	protected $_table_name = 'articles';

	public function getLastNews() {
		return DB::select()
			->from('articles')
			->where('type', '=', '0')
			->order_by('creation_date', 'DESC')
			->limit('2')
			->as_object()
			->execute();
	}

	public function getSome($type, $offset) {
		$items_per_page = Kohana::$config->load('main')->items_per_page;

		return DB::select()
			->from('articles')
			->where('type', '=', $type)
			->limit($items_per_page)
			->offset($offset)
			->as_object()
			->execute();
	}

	public function getOne($id) {
		return DB::select()
			->from('articles')
			->where('id', '=', $id)
			->as_object()
			->execute()
			->current();
	}

	public function countAll($type) {
		return DB::select('id')
			->from('articles')
			->where('type', '=', $type)
			->as_object()
			->execute()
			->count();
	}
}